package com.test.kotlin07

class MagicBox<T>(item:T) {//定义泛型

    var  available = true
    private var subject:T= item

    fun fetch():T?{//泛型函数
        return subject.takeIf {  available }
    }



}


class Boy(val name:String, val age:Int)

class Dog(val weight:Int)

fun main() {
    var b: MagicBox<Boy> = MagicBox(Boy("Jack",30))
    var d: MagicBox<Dog> = MagicBox(Dog(10))

    b.fetch()?.run {
        println("you find $name")
    }
}

